package com.example.testcomposeproject.pages.testChart

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.testcomposeproject.PreViewData
import com.example.testcomposeproject.ui.theme.AppTheme

import android.graphics.Color
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.charts.PieChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.PieData
import com.github.mikephil.charting.data.PieDataSet
import com.github.mikephil.charting.data.PieEntry

/**
 * @author: hemin
 * @date: 2024/6/21
 * @Desc:
 */
@Preview(showBackground = true, device = PreViewData.PreviewPhoneSize)
@Composable
fun PreViewTestLineChartUI(modifier: Modifier = Modifier) {
    AppTheme {
        BarChartView()

    }
}


@Composable
fun BarChartView() {
    AndroidView(
        modifier = Modifier
            .fillMaxWidth()
            .height(300.dp)
            .padding(16.dp),
        factory = { context ->
            BarChart(context).apply {
                description.isEnabled = false
                legend.isEnabled = false
                // Set bar chart data
                val entries = listOf(
                    BarEntry(0f, 10f),
                    BarEntry(1f, 20f),
                    BarEntry(2f, 30f)
                )
                val dataSet = BarDataSet(entries, "Bar Chart").apply {
                    colors = listOf(
                        Color.RED,
//                        Color.GREEN,
//                        Color.BLUE
                    )
                }
                data = BarData(dataSet)
            }
        },
        update = { barChart ->
            // Update bar chart data here
            barChart.invalidate() // Refresh chart
        }
    )
}